<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class ProductType extends Model
{
    use HasFactory;


    protected $table = 'product_type';

    protected $primaryKey = 'id';

    public $timestamps = false;

    public function getList(array $params): array
    {
        $whereSql = self::conditions($params);

        $sql = "
            SELECT
                pt.*
            FROM
                product_type pt
            WHERE
                pt.delete_flg = 0
                {$whereSql}
        ";
        return DB::select($sql);
    }

    public static function conditions(array $params): string
    {
        $whereSql = "";

        if (!empty($params['id'])) {
            $whereSql .= "and pt.id = '{$params['id']}'";
        }
        if (!empty($params['status'])) {
            $whereSql .= "and pt.status = '{$params['status']}'";
        }

        return $whereSql;
    }
}
